//
//  SecondCustonmeSegue.swift
//  Transition2
//
//  Created by Open on 2/3/15.
//  Copyright (c) 2015 open-groupe. All rights reserved.
//

import UIKit

class SecondCustonmeSegue: UIStoryboardSegue {

    override func perform() {
       var   firstVCView = self.sourceViewController.view as UIView!
        var secondView   = self.destinationViewController.view as UIView!
        
        let widow = UIApplication.sharedApplication().keyWindow
        widow?.insertSubview(secondView, aboveSubview: firstVCView)
        
        secondView.transform = CGAffineTransformScale(secondView.transform, 0.001, 0.001)
        
        UIView.animateWithDuration(0.5, animations: {
            () -> Void in
            firstVCView.transform = CGAffineTransformScale(secondView.transform, 0.001, 0.001)
        })
            {(finished) -> Void in
                UIView.animateWithDuration(0.5, animations: {
                    secondView.transform = CGAffineTransformIdentity
                    self.sourceViewController.presentViewController(self.destinationViewController as UIViewController, animated: false, completion: nil)
                })
        }
    }
}
